import { MICRO_SERVICE_ADMIN } from '~/constants/service-constant.ts'
import type { ComponentReq, ComponentResp } from '~/api/setting/model/component.ts'

enum Api {
  QueryComponentListByMenuId = '/webservice/component/queryComponentListByMenuId',
  QueryComponentCheckedListByMenuIdOfPermissionId = '/webservice/component/queryComponentCheckedListByMenuIdOfPermissionId',
  CreateComponent = '/webservice/component/createComponent',
  ModifyComponent = '/webservice/component/modifyComponent',
  EnabledComponentStateById = '/webservice/component/enabledComponentStateById',
  RemoveComponentById = '/webservice/component/removeComponentById',
}

/**
 * 获取UI组件树
 * @param params UI组件实体
 */
export function queryComponentListByMenuIdApi(params?: ComponentReq) {
  return usePost<ComponentResp[], ComponentReq>(MICRO_SERVICE_ADMIN + Api.QueryComponentListByMenuId, params)
}

/**
 * 根据菜单ID，获取根据权限ID标记UI组件列表
 * @param params UI组件实体
 */
export function queryComponentCheckedListByMenuIdOfPermissionIdApi(params?: ComponentReq) {
  return usePost<ComponentResp[], ComponentReq>(MICRO_SERVICE_ADMIN + Api.QueryComponentCheckedListByMenuIdOfPermissionId, params)
}

/**
 * 创建UI组件
 * @param params UI组件实体
 */
export function createComponentApi(params?: ComponentReq) {
  return usePost<ComponentResp, ComponentReq>(MICRO_SERVICE_ADMIN + Api.CreateComponent, params)
}

/**
 * 修改UI组件
 * @param params UI组件实体
 */
export function modifyComponentApi(params?: ComponentReq) {
  return usePost<ComponentResp, ComponentReq>(MICRO_SERVICE_ADMIN + Api.ModifyComponent, params)
}

/**
 * 开启或关闭组件状态
 * @param params 组件实体
 */
export function enabledComponentStateByIdApi(params?: ComponentReq) {
  return useGet<boolean, ComponentReq>(MICRO_SERVICE_ADMIN + Api.EnabledComponentStateById, params)
}

/**
 * 删除UI组件
 * @param params UI组件实体，使用其中ID
 */
export function removeComponentByIdApi(params?: ComponentReq) {
  return useGet<boolean>(MICRO_SERVICE_ADMIN + Api.RemoveComponentById, params)
}
